package com.wz.project.barcodeMsg.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.project.barcodeMsg.domain.BarcodeMsg;
import com.wz.project.barcodeMsg.service.IBarcodeMsgService;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.web.page.TableDataInfo;

import javax.xml.crypto.Data;

/**
 * 条码采集Controller
 * 
 * @author wld
 * @date 2023-10-16
 */
@Controller
@RequestMapping("/barcodeMsg/barcodeMsg")
public class BarcodeMsgController extends BaseController
{
    private String prefix = "barcodeMsg/barcodeMsg";

    @Autowired
    private IBarcodeMsgService barcodeMsgService;

//    @RequiresPermissions("barcodeMsg:barcodeMsg:view")
    @GetMapping()
    public String barcodeMsg()
    {
        return prefix + "/barcodeMsg";
    }

    /**
     * 查询条码采集列表
     */
//    @RequiresPermissions("barcodeMsg:barcodeMsg:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BarcodeMsg barcodeMsg)
    {
        startPage();
        List<BarcodeMsg> list = barcodeMsgService.selectBarcodeMsgList(barcodeMsg);
        return getDataTable(list);
    }

    /**
     * 导出条码采集列表
     */
//    @RequiresPermissions("barcodeMsg:barcodeMsg:export")
    @Log(title = "条码采集", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BarcodeMsg barcodeMsg)
    {
        List<BarcodeMsg> list = barcodeMsgService.selectBarcodeMsgList(barcodeMsg);
        ExcelUtil<BarcodeMsg> util = new ExcelUtil<BarcodeMsg>(BarcodeMsg.class);
        return util.exportExcel(list, "barcodeMsg");
    }

    /**
     * 新增条码采集
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存条码采集
     */
    @RequiresPermissions("barcodeMsg:barcodeMsg:add")
    @Log(title = "条码采集", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BarcodeMsg barcodeMsg)
    {
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        barcodeMsg.setCreateTime(date);
        return toAjax(barcodeMsgService.insertBarcodeMsg(barcodeMsg));
    }

    /**
     * 修改条码采集
     */
    @GetMapping("/edit/{barcode}")
    public String edit(@PathVariable("barcode") String barcode, ModelMap mmap)
    {
        BarcodeMsg barcodeMsg = barcodeMsgService.selectBarcodeMsgById(barcode);
        mmap.put("barcodeMsg", barcodeMsg);
        return prefix + "/edit";
    }

    /**
     * 修改保存条码采集
     */
    @RequiresPermissions("barcodeMsg:barcodeMsg:edit")
    @Log(title = "条码采集", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BarcodeMsg barcodeMsg)
    {
        return toAjax(barcodeMsgService.updateBarcodeMsg(barcodeMsg));
    }

    /**
     * 删除条码采集
     */
    @RequiresPermissions("barcodeMsg:barcodeMsg:remove")
    @Log(title = "条码采集", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(barcodeMsgService.deleteBarcodeMsgByIds(ids));
    }
}
